xed=720:yed=576
setdisplay(xed,yed,32,1):paper(8^8-1):ink(0):pen(0):cls
while 0=0
  setcaption("webcam")
  shell("fswebcam -d /dev/video0 -r 800x600 _tmpr1.jpg")
  'shell("fswebcam -d /dev/video0 _tmpr1.jpg")
  setcaption("imagemagick")
  shell("convert _tmpr1.jpg -resize 720x576\\! _tmpr2.png && sync && rm _tmpr1.jpg")
  setcaption("load")
  loadimage("_tmpr2.png",1):pasteicon(0,0,1)
  setcaption("convert")

  for y=0 to yed-1
    ro=0:go=0:bo=0
    for x=0 to xed-1 step 2
      ind=point(x,y)
      b=ind mod 256:ind=int(ind/256)
      g=ind mod 256:ind=int(ind/256)
      r=ind mod 256
      k=((b*11)+(r*30)+(g*59))/100
      b2=(int(b/16))*255/15
      g2=(int(g/16))*255/15
      r2=(int(r/16))*255/15
      k2=(int(k/16))*255/15
      bd=abs(b2-bo)
      rd=abs(r2-ro)
      gd=abs(g2-go)

      tg=0
      'if r2<>ro and g2<>go and b2<>bo then:bo=k2:ro=k2:go=k2:tg=1:end if
      if bd>=rd and bd>=gd and tg=0 then:bo=b2:tg=1:end if
      if rd>=bd and rd>=gd and tg=0 then:ro=r2:tg=1:end if
      if gd>=rd and gd>=bd and tg=0 then:go=g2:tg=1:end if

      ink(rgb(ro,go,bo))
      line(x,y,x+1,y)
      next:next


wait(3000)
wend




' grab (1,0,0,xed,yed):saveimage(fout$,1)
' shell ("convert "+finp$+".bmp "+finp$+".png")
' shell ("rm "+finp$+".bmp")



